﻿using MediatR;
using Traceability.APP.Application.Command.Enterprise;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrerture.Interfaces;

namespace Traceability.APP.Application.CommandHandle.Enterprise
{
    /// <summary>
    /// 养殖企业的显示
    /// </summary>
    public class ShowEnterpriseCommandHandle:IRequestHandler<ShowEnterpriseCommand,APIResult<List<Enterprise_Model>>>
    {
        private readonly IBaseRepository<Enterprise_Model> EnterpriseDal;

        public ShowEnterpriseCommandHandle(IBaseRepository<Enterprise_Model> enterpriseDal)
        {
            EnterpriseDal = enterpriseDal;
        }


        Task<APIResult<List<Enterprise_Model>>> IRequestHandler<ShowEnterpriseCommand, APIResult<List<Enterprise_Model>>>.Handle(ShowEnterpriseCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Enterprise_Model>> result = new APIResult<List<Enterprise_Model>>();
            var list = EnterpriseDal.GetAll().Where(x => x.Batch == request.Batch && x.IsDeleted == false);
            result.Code = StateCode.Ok;
            result.Message = StateCode.Ok.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }



    }
}
